<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['namespace'=>'Api\v2'], function (){
    Route::any('login', 'LoginController@index');
    Route::any('register', 'RegisterController@index');
    Route::any('account/signup', 'RegisterController@index');
    Route::any('/apns/device_token', 'ApnsController@deviceToken');
    Route::any('/apns/jpush', 'ApnsController@jpush');
    //district
    Route::get('/district/get', 'DistrictController@get');
    Route::get('/district/getdistrictlist', 'DistrictController@getDistrictList');
    //block
    Route::any('/block/getitemlist', 'BlockController@getItemList');
    Route::any('/tuijian', 'IndexController@tuijian');
    Route::any('/youxuan', 'IndexController@youxuan');
    Route::any('/itempush/getitemlist', 'ItemPushController@getItemList');
    //item
    Route::any('/item/getitem', 'ItemController@getItem');
    Route::any('/item/getitemlist', 'ItemController@getItemList');
    Route::any('/item/getcatlog', 'ItemController@getCatlog');
    Route::any('/item/getcatloglist', 'ItemController@getCatlogList');
    Route::any('/item/getcatlogtree', 'ItemController@getCatlogTree');
    //shop
    Route::any('/shop/getshop', 'ShopController@getShop');
    Route::any('/shop/getshoplist', 'ShopController@getShopList');
    //post
    Route::any('/post/getitemlist', 'PostController@getItemList');
    Route::any('/post/getcatloglist', 'PostController@getCatlogList');
    //express
    Route::any('/express/getexpresslist', 'ExpressController@getExpressList');
    //pages
    Route::any('/pages/getpage', 'PagesController@getPage');
    //feedback
    Route::any('/feedback/save', 'FeedbackController@save');

    Route::group(['middleware'=>'auth:api'], function (){
        //cart
        Route::any('/cart/getitemlist', 'CartController@getItemList');
        Route::any('/cart/add', 'CartController@add');
        Route::any('/cart/updatequantity', 'CartController@updateQuantity');
        Route::any('/cart/settlement', 'CartController@settlement');
        //order
        Route::any('/auction/createorder', 'AuctionController@createOrder');
        Route::any('/auction/settlement', 'AuctionController@settlement');
        Route::any('/order/getorder', 'OrderController@getOrder');
        Route::any('/order/getorderlist', 'OrderController@getOrderList');
        Route::any('/order/closeorder', 'OrderController@closeOrder');
        Route::any('/order/confirmorder', 'OrderController@confirmOrder');
        //address
        Route::any('/address/getaddress', 'AddressController@getAddress');
        Route::any('/address/getaddresslist', 'AddressController@getAddressList');
        Route::any('/address/setdefault', 'AddressController@setDefault');
        Route::any('/address/delete', 'AddressController@delete');
        Route::any('/address/save', 'AddressController@save');
        //pay
        Route::any('/alipay/sign', 'AlipayController@sign');
        Route::any('/alipay/query', 'AlipayController@query');
        //user
        Route::any('/user/info', 'UserController@info');
        Route::any('/user/update', 'UserController@update');
        Route::any('/user/avatar', 'UserController@avatar');
        //security
        Route::any('/security/editpass', 'SecurityController@editPass');
        Route::any('/security/bindmobile', 'SecurityController@bindMobile');
        Route::any('/security/bindemail', 'SecurityController@bindEmail');
        //Collection
        Route::any('/collect/add', 'CollectController@add');
        Route::any('/collect/getitemlist', 'CollectController@getItemList');
        Route::any('/collection/add', 'CollectController@add');
        Route::any('/collection/getitemlist', 'CollectController@getItemList');
        //material
        Route::any('/material/uploadimage', 'MaterialController@uploadImage');
    });

    //version
    Route::any('/version', function (){
        $userAgent = 'time:'.time().','.$_SERVER['HTTP_USER_AGENT'];
        if(strpos($userAgent, 'Android') || strpos($userAgent, 'okhttp')){
            return ajaxReturn(['version'=>3.8, 'userAgent'=>$userAgent]);
        } else {
            return ajaxReturn(['version'=>3.8, 'userAgent'=>$userAgent]);
        }
    });
    //检测登录状态
    Route::get('/checklogin', 'IndexController@checklogin')->middleware('auth:api');
    Route::any('/food', 'IndexController@food');
    Route::any('/nutritious', 'IndexController@nutritious');
    Route::any('/fupin', 'IndexController@fupin');

    Route::any('/test', 'IndexController@test')->middleware('auth:api');


});
